package com.example.offer.no0016.impl;

import com.example.offer.no0016.Solution;

public class SolutionImpl implements Solution {

    @Override
    public double myPow(double x, int n) {

        if (x == 0) {
            return 0;
        }
        if (n == 0) {
            return 1;
        }
        if (n < 0) {
            x = 1 / x;
            n = -n;
        }

        double res = 1;
        while (n > 0) {
            if ((n & 1) == 1) {
                res = res * x;
            }
            x *= x;
            n >>= 1;
        }

        return res;
    }
}
